import { http } from "@/lib"
import apis from "@/apis"

export function getDealerListByBrand(code) {
  return new Promise((resolve, reject) => {
    http.get(apis.GetDealerListByBrand, { params: { brandCode: code, agentType: 0 } }).then(res => {
      const dealerOptions = res.data?.map(({ agentCode: value, agentName: title }) => ({ value, title })) || []
      resolve(dealerOptions)
    }).catch(() => reject())
  })
}

export function getBrandSelectList() {
  return new Promise((resolve, reject) => {
    http.get(apis.BrandCompanySelectList).then(res => {
      const brandOptions = res.data?.map(({ brandCode: value, brandInfoName: title }) => ({ value, title })) || []
      resolve(brandOptions)
    }).catch(() => reject())
  })
}